package cn.cdliux.spring.core.io;

import cn.hutool.core.lang.Assert;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 通过文件系统读取资源文件
 * @author liuxiang
 */
public class FileSystemResurce implements Resource {

    private final File file;

    private final String path;

    public final String getPath() {
        return path;
    }


    public FileSystemResurce(File file) {
        this.file = file;
        this.path = file.getPath();
    }

    public FileSystemResurce(String path) {
        Assert.notNull(path,"Path must not be null.");
        this.file = new File(path);
        this.path = path;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return new FileInputStream(this.file);
    }
}
